/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.idea.utils.sfo.designer;


import designersfo.Cons;
import designersfo.Cons.CellInfo;
import designersfo.Cons.CellInfo.CellFormat;
import designersfo.Cons.CellInfo.CustomContentCellData;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;


/**
 *
 * @author renke002
 */
public class DesignerCol extends DesignerGraphic implements PropertyChangeListener
{

    /**
     *
     */
    private Cons cons;
    /**
     *
     */
    private Integer colNumber;
    /**
     *
     */
    private Integer rowNumber;
    /**
     *
     */
    private Long cellHeight;
    /**
     *
     */
    private Long cellWidth;
    /**
     * True if this cell is Horizontally Joined with the adjacent one(s).
     */
    private boolean isJoinedHoriz;
    /**
     * True if this cell is Vertically Joined with the adjacent one(s).
     */
    private boolean isJoinedVert;


    /**
     *
     * @param cons
     * @param colNum
     * @param rowNum
     * @param myHeight
     * @param prevHeights
     * @param myWidth
     * @param prevColWidths
     */
    public DesignerCol( Cons cons , Integer colNum , Integer rowNum , Long myHeight , Long prevHeights , Long myWidth , Long prevColWidths )
    {
        super( rowNum , colNum , myWidth , myHeight , prevColWidths , prevHeights );

        this.cons = cons;
        this.colNumber = colNum;
        this.rowNumber = rowNum;
        this.cellHeight = myHeight;
        this.cellWidth = myWidth;
    }


    /**
     * Returns 'true' if this element contains Cell-Data.
     *
     * @return
     */
    public boolean containsCellData()
    {
        /*
         * In order to contain Cell-Data, the element must contain a Cell-Info object.
         */
        if ( this.containsCellInfo() )
        {
            if ( this.getCellInfo().getCustomContentCellData().isEmpty() == false )
            {
                // The set of Cell-Data object(s) is not empty, so there is some
                // custom content data associated with this element.
                return true;
            }
        }
        return false;
    }


    /**
     * Return 'true' if this element contains Cell-Format data.
     *
     * @return
     */
    public boolean containsCellFormat()
    {
        /*
         * In order to contain Cell-Format, the element must contain Cell-Info.
         */
        if ( this.containsCellInfo() )
        {
            if ( this.getCellInfo().getCellFormat().isEmpty() == false )
            {
                // The set of Cell-Format object(s) is not empty, so there is some
                // formatting data associated with this element.
                return true;
            }
        }
        return false;
    }


    /**
     * Returns true if this element contains Cell-Info data.
     *
     * If false, then this is either an empty element or, at most, contains
     * row-info that's only useful to determine the height of this row.
     *
     * @return
     */
    public boolean containsCellInfo()
    {
        if ( this.cons.getCellInfo().isEmpty() == false )
        {
            return true;
        } else
        {
            return false;
        }
    }


    /**
     *
     * @return
     */
    public CustomContentCellData getCellData()
    {
        CustomContentCellData cd = null;
        if ( this.containsCellData() )
        {
            cd = this.getCellInfo().getCustomContentCellData().get( DesignerRowChildren.FIRST_ELEMENT );
        }
        return cd;
    }


    /**
     *
     * @return
     */
    public CellFormat getCellFormat()
    {
        CellFormat cf = null;
        if ( this.containsCellFormat() )
        {
            cf = this.getCellInfo().getCellFormat().get( DesignerRowChildren.FIRST_ELEMENT );
        }
        return cf;
    }


    /**
     *
     * @return
     */
    private CellInfo getCellInfo()
    {
        CellInfo ci = null;
        if ( this.containsCellInfo() )
        {
            ci = this.cons.getCellInfo().get( DesignerRowChildren.FIRST_ELEMENT );
        }
        return ci;
    }


    /**
     *
     * @return
     */
    public Integer getColNumber()
    {
        return this.colNumber;
    }


    /**
     *
     * @return
     */
    public long getHeight()
    {
        return this.cellHeight;
    }


    /**
     *
     * @return
     */
    public String getName()
    {
        return "Col: " + this.colNumber;
    }


    /**
     *
     * @return
     */
    public Integer getRowNumber()
    {
        return this.rowNumber;
    }


    /**
     *
     * @return
     */
    public long getWidth()
    {
        return this.cellWidth;
    }


    /**
     *
     * @return
     */
    public void setName( String newName )
    {
        // TO-DO: replace this with useful code.
        String oldValue = this.getName();
        this.cons.getCellInfo().get( 0 ).getCellFormat().get( 0 ).setFontFamily( newName );
        System.out.println( "You entered " + this.cons.getCellInfo().get( 0 ).getCellFormat().get( 0 ).getFontFamily() );
        propertyChangeSupport.firePropertyChange( "ID" , oldValue , newName );
    }
    
    private transient final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
    
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }
    
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener( listener );
    }

    @Override
    public void propertyChange( PropertyChangeEvent evt )
    {
        propertyChangeSupport.firePropertyChange( evt );
    }

}
